import java.io.IOException;
import java.io.File;

import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioFileFormat;

public class Writer extends Thread {
    private static final int EXTERNAL_BUFFER_SIZE = 128000;
    private TargetDataLine m_line;
    private AudioFileFormat.Type m_targetType;
    private AudioInputStream m_audioInputStream;
    private String m_outputFile;
    private Track[] track = new Track[20];
    private int i;
    File outputFile;
    private char c;

    // given an output file and an audio in, writer writes whatever to the file
    public Writer(TargetDataLine line, AudioFileFormat.Type targetType,
            File file) {
        m_line = line;
        m_audioInputStream = new AudioInputStream(line);
        m_targetType = targetType;
        outputFile = file;
    }

    public void start() {
        m_line.start();
        super.start();
    }

    public void stopRecording() {
        m_line.stop();
        m_line.close();

    }

    public void run() {

        try {
            AudioSystem.write(m_audioInputStream, m_targetType, outputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static void print(String line) {
        System.out.println(line);
    }

    private static void out(String strMessage) {
        System.out.println(strMessage);
    }
}

/*** Writer.java ***/
